package sort;

public class Bubble {
    public static void main(String[] args) {
        int[] ints = {50,8,75,54,78,24,64,99};
        bubble(ints);
        for (int i = 0; i < ints.length; i++) {
            System.out.println(ints[i]);
        }
    }
    public static void bubble(int[] arr){
        for (int i = 0; i < arr.length -1; i++) {//n个数排序只需要n-1次
            /**
             * (-i-1) -i 是因为每次外层循环把最大值放到后面了，无需对比，-1是防止数组越界
             */
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] > arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
    }
}
